<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('违法行为类型')" prop="illegalType">
            <el-input v-model="form.illegalType" :placeholder="$t('违法行为类型')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('作出行政处罚决定机关名称')" prop="deptName">
            <el-input v-model="form.deptName" :placeholder="$t('作出行政处罚决定机关名称')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('作出行政处罚决定日期')" prop="decisionDate">
            <DatePicker v-model="form.decisionDate" :placeholder="$t('作出行政处罚决定日期')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('公示日期')" prop="publishDate">
            <DatePicker v-model="form.publishDate" :placeholder="$t('公示日期')" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('性质处罚决定书文号')" prop="punishNumber">
            <el-input v-model="form.punishNumber" :placeholder="$t('性质处罚决定书文号')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('行政处罚内容')" prop="punishContent">
            <el-input v-model="form.punishContent" type="textarea" :placeholder="$t('行政处罚内容')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div v-show="!btnHide" slot="footer" class="dialog-footer" style="text-align: right;">
      <!--保存，保存并启动流程，取消 三个按钮-->
      <SaveBtn has-permi="company:punish" :save-show="sourceType !== 'bussRisk'" />
    </div>
  </div>
</template>

<script>
    import { saveCompanyAdstPunish, getCompanyAdstPunish } from '@/api/company/punish/companyAdstPunish'
    export default {
        props: {
          sourceType: {
            type: String,
            default: ''
          }
        },
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  illegalType: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  deptName: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  decisionDate: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                // 是否隐藏保存等按钮
                btnHide: false
            }
        },
        created() {
        },
        mounted() {
          this.$bus.$emit('async_done')
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getCompanyAdstPunish(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
                this.form.companyId = this.$route.query.companyId
            },
            // 表单重置
            reset() {
                this.form = {
                id: undefined,
                companyId: undefined,
                illegalType: undefined,
                deptName: undefined,
                decisionDate: undefined,
                publishDate: undefined,
                punishNumber: undefined,
                punishContent: undefined,
                createBy: undefined,
                createTime: undefined,
                updateBy: undefined,
                updateTime: undefined,
                delFlag: undefined,
                remark: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                this.$parent.$parent.formOpen = false
                // 刷新list页面
                this.$parent.$parent.getList()
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        this.form.source = '1'
                        saveCompanyAdstPunish(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                              if (this.$route.query.companyId) {
                                this.$store.dispatch('bussRisk/UPDATE_BUSS_RISK_COUNT', { id: this.$route.query.companyId })
                              }
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        }).catch(() => {
                          this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
